#include <REGX52.H>
#include <intrins.h>

sfr AUXR = 0x8e;
sbit D5 = P3^7;
char cmd;


void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


void InitUart(){

	TMOD &= 0x0F;
	TMOD |= 0x20;
	AUXR &= 0xBF;
	AUXR &= 0xFE;
	SCON  = 0x50;
	TH1   = 0xFD;
	TL1   = 0xFD;
	TR1   = 1;
	EA    = 1;
	ES    = 1;

}

void SendByte(char data_masg){
	
	SBUF = data_masg;
	while(!TI);
	TI = 0;
}

void Sendstring(char* str){

	while( *str != '\0'){
		
		SendByte(*str);
		str++;
	}
}

int main(){
	
	InitUart();
	
	while(1){
		
		Delay1000ms();
		Sendstring("suai666\r\n");
	}
}

void Uart_Handler() interrupt 4
{
	if(RI)//中断处理函数中，对于接收中断的响应
	{
		RI = 0;//清除接收中断标志位
		cmd = SBUF;
		if(cmd == 'o'){
			D5 = 0;//点亮D5
		}
		if(cmd == 'c'){
			D5 = 1;//熄灭D5
		}
	}
if(TI);
}